package app.imttf.internal.backing.login;

import app.imttf.internal.adfextensions.ADFUtils;

import java.io.IOException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import oracle.adf.controller.ControllerContext;

public class LogoutBean {

    public void logoutUser(ActionEvent evt) {
        try {
            FacesContext ctx = FacesContext.getCurrentInstance();
            ExternalContext ectx = ctx.getExternalContext();
            HttpServletResponse response =
                (HttpServletResponse)ectx.getResponse();
            HttpSession session = (HttpSession)ectx.getSession(false);
            
            ControllerContext cc = ControllerContext.getInstance();
            String logoutUrl = cc.getGlobalViewActivityURL("Login");
            
            session.invalidate();
            ctx.responseComplete();
            response.sendRedirect(logoutUrl);
            FacesContext.getCurrentInstance().responseComplete();
                        
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
